// pages/addimage/addimage.js
const SERVER = require('../../utils/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    stylename:'',
    name:'',
    idNumber:'',
    cardType:'',
    qimg:'',
    himg:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      cardType:options.stylename
    })
 
  
  },
name(e){
  this.setData({
    name:e.detail.value
  })

},
tel(e){
  this.setData({
    idNumber:e.detail.value
  })
},
tijiao(){
  var that=this
  let param = {
    cartNo : that.data.idNumber,
    cardType : that.data.cardType=='中华人民共和国居民身份证'?'0':'4',
    source : 1,
    countryType:0,
    realname:this.data.name,
    userPicFront:that.data.qimg,
    userPicBack:that.data.himg
  }
  wx.request({//首页数据
    url: '' + SERVER.SERVER_DIMAIN + '/admin/appuser/edituser', 
    data:JSON.stringify(param),
    header: {
      'content-type': 'application/json' ,
      "TENANT-ID":"2",
      "Connection":'Keep-alive',
      "Accept-Encoding":'gzip,deflate,br',
      "Authorization":"Bearer "+wx.getStorageSync('token'),
      "DEVICE_TYPE":'IOS'
    },
    method: 'post',
    success: function (res) {
      console.log(res)
      that.setData({
        list:res.data.data
      })
      
      // that.setData({
      //   list:res.data.data
      // })
      
   
     
    }
  });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  add(){
    //上传图片
     var that = this;
 wx.chooseImage({
   success: function(res) {
     var tempFilePaths = res.tempFilePaths
     wx.uploadFile({
       url: 'https://pre.admin.chengxuan.e-troin.cn/fastdfs/file/upload/image/sample', //仅为示例，非真实的接口地址
       filePath: tempFilePaths[0],
       name: 'file',
       formData:{
         'user': 'test'
       },
       success: function(res){
         let filename=JSON.parse(res.data)
       
         that.setData({
           qimg:filename.data.fileName
         })
        
       }
     })
   }
 })
    
 
 },
 adds(){
  //上传图片
   var that = this;
wx.chooseImage({
 success: function(res) {
   var tempFilePaths = res.tempFilePaths
   wx.uploadFile({
     url: 'https://pre.admin.chengxuan.e-troin.cn/fastdfs/file/upload/image/sample', //仅为示例，非真实的接口地址
     filePath: tempFilePaths[0],
     name: 'file',
     formData:{
       'user': 'test'
     },
     success: function(res){
      let filename=JSON.parse(res.data)
       
      that.setData({
        himg:filename.data.fileName
      })
     }
   })
 }
})
  

},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})